package com.example.musicplayer;

import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

public class SongListFragment extends Fragment {

    private RecyclerView recyclerView;
    private SongAdapter songAdapter;
    private List<Song> songList;

    public SongListFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_song_list, container, false);

        recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        // 初始化歌曲列表
        songList = new ArrayList<>();
        songList.add(new Song("Cruel Summer", "Taylor Swift", "Lover", "我喜欢的音乐"));
        songList.add(new Song("才二十三", "方大同", "梦想家 The Dreamer", "我喜欢的音乐"));
        songList.add(new Song("告白气球", "周杰伦", "周杰伦的床边故事", "我喜欢的音乐"));
        songList.add(new Song("不爱我就拉倒", "周杰伦", "最伟大的作品", "我喜欢的音乐"));
        songList.add(new Song("可以了", "陈奕迅", "Rice & Shine(米·闪)", "我喜欢的音乐"));
        songList.add(new Song("匆匆那年", "王菲", "(电影《匆匆那年》同名主题曲)", "我喜欢的音乐"));
        songList.add(new Song("遗失的心跳", "萧亚轩", "我爱我 (心跳100影音庆功版)", "我喜欢的音乐"));
        songList.add(new Song("南方姑娘", "赵雷", "赵小雷", "我喜欢的音乐"));
        songList.add(new Song("作曲家", "李荣浩", "李荣浩", "我喜欢的音乐"));
        songList.add(new Song("水乡", "毛不易", "小王", "我喜欢的音乐"));

        songAdapter = new SongAdapter(songList, getContext());
        recyclerView.setAdapter(songAdapter);

        return view;
    }
}
